<template>
	<view>
		<image src="../../static/png/panel2.png" class="bg-img" :style="{height:screenHeight+'px'}"></image>
		<view class="title">登陆系统</view>
		<view class="login-form">
			<view class="form-item">
				<view class="item-label">账号</view>
				<view class="item-input-right">
					<input type="text" placeholder="请输入账号" v-model="formData.s_id">
				</view>
			</view>
			<view class="form-item">
				<view class="item-label">密码</view>
				<view class="item-input-right">
					<input type="text" password="true" placeholder="请输入密码" v-model="formData.pwd">
				</view>
			</view>
			<button @tap="loginSys()" type="primary" size="default" class="btn-login">登陆</button>
		</view>
	</view>
</template> 

<script>
	import pageHeader from "../../components/pageHeader.vue";
	import {mapGetters} from 'vuex';
	import AppConfig from "../../config/AppConfig.js";
	export default {
		name:"login",
		data(){
			return {
				formData:{
					s_id:uni.getStorageSync("s_id"),
					pwd:"" 
				},
				screenHeight:0
			} 
		},
		components:{
			pageHeader
		},
		onLoad:function(){
			this.screenHeight=uni.getSystemInfoSync().windowHeight;
		},
		methods:{
			loginSys(){
				var flag=true;
				for(var i in this.formData){
					if(this.formData[i]==null||this.formData[i]==""||this.formData[i]==undefined){
						flag=false;
					}
				}
				if(flag){
					uni.setStorageSync("s_id",this.formData.s_id);
					uni.showLoading({
						title:'正在登陆'
					});
					uni.request({
						url:`${AppConfig.baseUrl}/Stu_info/login/${this.formData.s_id}/${this.formData.pwd}`,
						success:function(res){
								uni.hideLoading();
								if(res.data.status=="success"){
								uni.setStorageSync('s_name',res.data.data.s_name);
								uni.setStorageSync("c_id",res.data.data.c_id);
								uni.reLaunch({
									url:'/pages/main/main',
									fail:function(e){
										console.log(e.detail); 
									},
									success:function(){
										console.log("success");
									}
								})
							}
							else{
								uni.showToast({
									title:res.data.msg,
									icon:"none"
								});
							}
						},
						fail:function(){
							uni.hideLoading();
							uni.showToast({
								title:'服务器错误'
							});
						}
					})
				}
				else{
					uni.showModal({
						title:'提示',
						content:'用户名与密码不能为空',
						showCancel:false
					});
				}
				
				
			}
		}
	}
</script>

<style scoped>
	.bg-img{
		position: fixed;
		left: 0px;
		top: 0px;
		width: 100%;
		z-index: -1;
	}
	.title{
		text-align: center;
		font-size: 44px;
		margin-top: 100px;
		color: white;
	}
	.login-form{
		margin-top: 150px;
		box-sizing: border-box;
		padding: 0px 20px;
	}
	.form-item{
		display: flex;
		flex-direction: row;
		height: 80px;
		margin-top: 10px;
		background-color: transparent;
		outline:1px solid  #2FA3DF;
	}
	.item-label{
		width: 170px;
		display: flex;
		height: 80px;
		justify-content: center;
		text-align: center;
		align-items: center;
	}
	.item-input-right{
		flex: 1;
	}
	.item-input-right>input{
		width: 100%;
		height: 80px;
		
	}
	.btn-login{
		margin-top: 20px;
	}
	
</style>
